home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / crack_4.1-tar / Crack < prev    next >
Encoding:
Text File  |  1992-06-25  |  6.6 KB  |  327 lines

  1. #!/bin/sh
  2.  
  3. ###
  4. # This program is copyright Alec Muffett 1991, and is provided as part of
  5. # the Crack v4.1 Password Cracking package.  The author disclaims all
  6. # responsibility or liability with respect to it's usage or its effect
  7. # upon hardware or computer systems, and maintains copyright as set out in
  8. # the "LICENCE" document which accompanies distributions of Crack v4.0 and
  9. # upwards. So there...
  10. ###
  11.  
  12. ###
  13. # CRACK_HOME: You must put DOUBLE QUOTES around this and have /bin/csh if
  14. # you work relative to ~username - this is the Crack installation directory.
  15. # (currently developing on "dougal")
  16. ###
  17.  
  18. CRACK_HOME="~aem/dougal/crack41f"
  19.  
  20. ###
  21. # CRACK_OUT: This is the directory into which all the password guesser
  22. # output files are to be stored. This affects only the "out*" files, and
  23. # not "D*" or "P*", due to restraints on the support scripts.
  24. ###
  25.  
  26. CRACK_OUT="$CRACK_HOME"
  27.  
  28. ###
  29. # Umask for security's sake - stops files being world readable (if you
  30. # don't have it in your .login)
  31. ###
  32.  
  33. umask 077
  34.  
  35. ###
  36. # DEFAULT_BIN : For non-network cracks, you can leave this as 'generic'.
  37. # Setting this to `arch` is non-portable.
  38. ###
  39.  
  40. DEFAULT_BIN="generic"
  41.  
  42. ###
  43. # List of standard dictionaries that you should have to provide words;
  44. #
  45. ###
  46.  
  47. STDDICT="/usr/dict/words"
  48.  
  49. ###
  50. # Compress: name of a compression prog (compress & pack supported) to be
  51. # applied to the bigdict to save filespace
  52. ###
  53.  
  54. compress="/usr/ucb/compress"
  55.  
  56. ###
  57. ############### FROM HERE ON IN IT'S ALL MY FAULT ###############
  58. ###
  59.  
  60. version="4.1f RELEASE"            # version number
  61. pwl=""                    # user specified
  62. domail=""                # user specified
  63. fgnd=""                    # user specified
  64. remote=""                # program specified
  65. nice=""                    # user specified
  66. rcvr=""                    # user specified
  67. inputfile="/tmp/pw.$$"            # program specified, also in pwc.c
  68. verbose=""                # user specified
  69. cf_file="Scripts/network.conf"        # program specified
  70. bigdict="Dicts/bigdict"            # program specified
  71. lockdict="Dicts/.lockfile"        # program specified
  72.  
  73. CRACK_HOME_UNRES="$CRACK_HOME"
  74.  
  75. if [ -f "/bin/csh" ]            # -x bombs on Ultrix
  76. then
  77.     CRACK_OUT=` /bin/csh -fc "echo $CRACK_OUT" `
  78.     CRACK_HOME=` /bin/csh -fc "echo $CRACK_HOME" `
  79. fi
  80.  
  81. if [ ! -d "$CRACK_OUT" ]
  82. then
  83.     echo "Warning: CRACK_OUT directory reset to directory '.'"
  84.     CRACK_OUT="."
  85. fi
  86.  
  87. export CRACK_HOME
  88. export CRACK_OUT
  89. export DEFAULT_BIN
  90. export CRACK_HOME_UNRES
  91.  
  92. ###
  93. # Check existance of a home directory
  94. ###
  95.  
  96. if [ "$CRACK_HOME" != "" -a -d "$CRACK_HOME" ]
  97. then
  98.     cd $CRACK_HOME || exit 1
  99. else
  100.     echo "Fatal error: the directory $CRACK_HOME does not exist."
  101.     echo ""
  102.     echo "Please set the value of CRACK_HOME in the 'Crack' script to the name of
  103.     echo "the installation directory."
  104.     echo ""
  105.     echo "The current working directory is" `pwd`"
  106.     exit 1
  107. fi
  108.  
  109. ###
  110. # Announce ourselves.
  111. ###
  112.  
  113. echo "Crack $version, The Password Cracker (c) Alec D.E. Muffett, 1992"
  114. echo "Invoked as: $0 $*"
  115.  
  116. if [ $# = 0 ]
  117. then
  118.     echo "Usage:    $0 [options] [bindir] passwdfile [...]"
  119.     echo "Or:       $0 -network [options] passwdfile [...]"
  120.     echo "Options:-"
  121.     echo "    -v              - to produce verbose output"
  122.     echo "    -nnicevalue     - to run niced to 'nicevalue'"
  123.     echo "    -rpointfile     - to recover a crashed-out job"
  124.     echo "    -Rpointfile     - to recover (with verify) a crashed-out job"
  125.     echo "    -f        - to run in foreground (output to stdout)"
  126.     echo "    -m        - to mail the user a warning message if cracked"
  127.     exit 1
  128. fi
  129.  
  130. ###
  131. # Make the dictionaries. God this is SOOOOO much simpler...
  132. ###
  133.  
  134. if [ ! -f $lockdict ]
  135. then
  136.     echo "Making dictionary $bigdict - This may take some time..."
  137.     (
  138.         for dictfile in $STDDICT DictSrc/*
  139.         do
  140.             case $dictfile in
  141.                 *.Z)
  142.                     zcat $dictfile
  143.                     ;;
  144.                 *.z)
  145.                     pcat $dictfile
  146.                     ;;
  147.                 *)
  148.                     cat $dictfile
  149.                     ;;
  150.             esac
  151.         done
  152.     ) |
  153.     grep -v '^#' |
  154.     sort |
  155.     uniq > $bigdict
  156.  
  157. # I do not do "tr A-Z a-z" here because of words like LaTeX and
  158. # BiCapitalisation, which are potential passwords, but the structure of
  159. # which would be irrecoverably destroyed by lowercaseing.
  160.  
  161.     echo touch $lockdict        # for future refs.
  162.     touch $lockdict
  163.  
  164.     if [ "x$compress" != "x" -a -f "$compress" ]
  165.     then
  166.         echo $compress $bigdict
  167.         # if this fails, tweak the $compress definition above...
  168.         $compress $bigdict || exit 1
  169.     fi
  170. else
  171.     echo Dictionary Dicts/* intact
  172. fi
  173.  
  174. ###
  175. # Check your invocation...
  176. ###
  177.  
  178. if [ "x$1" = "x-network" ]
  179. then
  180.     shift
  181.     Scripts/Crack.network $*
  182.     exit 0
  183. fi
  184.  
  185. while :
  186. do
  187.     case $1 in
  188.         -network)
  189.             echo "Error: -network (if specified) must be first argument"
  190.             exit 1
  191.             ;;
  192.         -X*)
  193.             remote=$1
  194.             shift
  195.             ;;
  196.         -m*)
  197.             domail=$1
  198.             shift
  199.             ;;
  200.         -l*)
  201.             pwl=$1
  202.             shift
  203.             ;;
  204.         -f*)
  205.             fgnd=$1
  206.             shift
  207.             ;;
  208.         -n*)
  209.             nice=$1
  210.             shift
  211.             ;;
  212.         -r*)
  213.             rcvr=$1
  214.             shift
  215.             ;;
  216.         -v*)
  217.             verbose=$1
  218.             shift
  219.             ;;
  220.         -*)
  221.             echo "Error: unknown argument $1"
  222.             shift
  223.             ;;
  224.         *)
  225.             break
  226.             ;;
  227.     esac
  228. done
  229.  
  230. ###
  231. # Test first non-switch argument for existance, hence where to put binaries
  232. ###
  233.  
  234. if [ -f "$1" ]
  235. then
  236.     CRACK_ARCH="$CRACK_HOME/$DEFAULT_BIN"
  237. else
  238.     CRACK_ARCH="$CRACK_HOME/$1"
  239.     shift
  240. fi
  241.  
  242. export CRACK_ARCH
  243.  
  244. echo "Binary directory: $CRACK_ARCH"
  245.  
  246. ###
  247. # Make the password cracker
  248. ###
  249.  
  250. Scripts/do_pwc $CRACK_ARCH || exit 1
  251.  
  252. ###
  253. # Process input to the program
  254. ###
  255.  
  256. echo "Sorting data for Crack."
  257.  
  258. if [ "x$remote" != "x" ]
  259. then
  260.     cat > $inputfile
  261. else
  262.     out_init=$CRACK_OUT/out.$$
  263.  
  264.     Scripts/do_join $out_init $* > $inputfile || exit 1
  265.  
  266.     if [ "x$domail" != "x" ]
  267.     then
  268.         MISCREANTS=`awk '/Guessed/{print $6}' < $out_init`
  269.         echo Sending Warning Mail to $MISCREANTS
  270.         Scripts/nastygram $MISCREANTS
  271.     fi
  272.  
  273.     if [ "x$fgnd" != "x" ]
  274.     then
  275.         cat $out_init || exit 1
  276.         rm -f $out_init
  277.     fi
  278. fi
  279.  
  280. ###
  281. # Check the runtime scratch file directory for pwc
  282. ###
  283.  
  284. if [ ! -d Runtime ]
  285. then
  286.     echo "Creating Runtime Directory."
  287.     mkdir Runtime || exit 1
  288. fi
  289.  
  290. ###
  291. # Kick it off into the background ?
  292. ###
  293. # This is the message which has drawn the most complaints...  However, I
  294. # have no way of knowing the name in advance, and I can't have crack-pwc
  295. # print it on stdout due to hanging file descriptors which bollox a
  296. # network crack.  Hence I HAVE to be vague...
  297. ###
  298.  
  299. flags="$remote $fgnd $XXdomail $pwl $nice $rcvr $verbose -i $inputfile"
  300.  
  301. echo "Flags:" $flags Dicts/*
  302.  
  303. if [ "x$fgnd" != "x" ]
  304. then
  305.     echo "Running program in foreground"
  306.     $CRACK_ARCH/crack-pwc $flags Dicts/* < /dev/null 2>&1
  307. else
  308.     echo "Running program in background"
  309.     # Apollos/Suns need first 7 descriptors closed to bg properly
  310.     # from ksh - hence overkill - AEM
  311.     nohup $CRACK_ARCH/crack-pwc $flags Dicts/* </dev/null >/dev/null \
  312.         2>&1 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 9>&1 &
  313.     echo "Output will be written to a file in directory $CRACK_OUT"
  314.     echo "named 'out<something>'"
  315. fi
  316.  
  317. sleep 1
  318.  
  319. test -f nohup.out && rm nohup.out
  320.  
  321. ###
  322. # There are horrible timeraces involved in removing $tmpfile, so I dont.
  323. # Crack-pwc does. Still. Hohum.
  324. ###
  325.  
  326. exit 0
  327.